package com.ruoyi.ruoyiserver.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.ruoyiserver.service.TeacherInformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Api(tags = "上传接口")
@RestController
@RequestMapping("/person")
public class PeImportController {

    @Autowired
    private TeacherInformationService teacherInformationService;

    /*导入教师信息*/
    @ApiOperation("上传老师数据")
    @PostMapping("/import/teacher")
    public AjaxResult importInformationExcel(@RequestParam("file") MultipartFile file) throws IOException {
          return teacherInformationService.importExcel(file);
    }
    /*导出教师信息*/
    @ApiOperation("导出教师数据")
    @PostMapping("/expert/teacher")
    public AjaxResult expertInformationExcel() throws IOException {
        byte[] bytes = teacherInformationService.generateExcelFile();
        return AjaxResult.success(bytes);
    }

    /*导入学生信息*/
    @ApiOperation("上传学生数据")
    @PostMapping("/import/student")
    public AjaxResult importStudentInformationExcel(@RequestParam("file") MultipartFile file) throws IOException {
            return teacherInformationService.importStudentExcel(file);
    }
    /*导出教师信息*/
    @ApiOperation("导出学生数据")
    @PostMapping("/expert/student")
    public AjaxResult expertStudentInformationExcel() throws IOException {
        byte[] bytes = teacherInformationService.generateExcelFile();
        return AjaxResult.success(bytes);
    }
    /*导入权利人信息*/
    @ApiOperation("上传权利人数据")
    @PostMapping("/import/obligee")
    public AjaxResult importObligeeInformationExcel(@RequestParam("file") MultipartFile file) throws IOException {
            return teacherInformationService.importObligeeExcel(file);
    }
    /*导出权利人信息*/
    @ApiOperation("导出权利人数据")
    @PostMapping("/expert/obligee")
    public AjaxResult expertObligeeInformationExcel() throws IOException {
        byte[] bytes = teacherInformationService.generateObligeeExcelFile();
        return AjaxResult.success(bytes);
    }

    /*导入网签信息*/
    @ApiOperation("上传网签数据")
    @PostMapping("/import/tab")
    public AjaxResult importTabInformationExcel(@RequestParam("file") MultipartFile file) throws IOException {
            return teacherInformationService.importTabExcel(file);
    }
    /*导出网签信息*/
    @ApiOperation("导出网签数据")
    @PostMapping("/expert/tab")
    public AjaxResult expertTabInformationExcel() throws IOException {
        byte[] bytes = teacherInformationService.generateTabExcelFile();
        return AjaxResult.success(bytes);
    }

    /*导入全部信息*/
    @ApiOperation("上传全部数据")
    @PostMapping("/import/information")
    public AjaxResult importInformation(@RequestParam("file") MultipartFile file) throws IOException {
        return teacherInformationService.importInformation(file);
    }
}
